//消息 页面
import React, { Component } from 'react'
import { withRouter } from "react-router-dom";
import Mytab from './Mytab'
import Avatar from './Me/Avatar'
import { Conget_tim } from '../TIM/actiontim';
import { connect } from 'react-redux'
import { imgInter } from '../data/Interface';
import '../business/Privatechat/message.css'

class Message extends Component {
    constructor(props) {
        super(props)
        this.state = {

        }
        this.props.dispatch(Conget_tim())
    }
    // 传入手机号获得id为了适配kefu页面的代码加的处理函数
    getGetbusinessid = (phone) => {
        // console.log(phone)
        let businessinfo
        let arr = this.props.business.filter((item) => {
            return item.business_phone == phone
        })
        businessinfo = arr[0]
        return businessinfo
    }

    render() {
        return (
            <div style={{ minHeight: '100vh', display: 'flex', width: '100%' }}>
                <div style={{ backgroundColor: "#080904", minHeight: '100vh', display: 'flex', width: '100%' }}>
                    <div style={{ width: '100%', margin: '0 auto' }}>
                        <div style={{ borderBottomLeftRadius: '50px', borderBottomRightRadius: '50px', backgroundColor: '#2d2e29', textAlign: 'center', fontSize: '1.5em', fontWeight: 'bold', paddingTop: '35px', paddingBottom: '30px' }}>我的消息</div>
                        {/* <div style={{ width: '100%', }}> */}
                        <ul className="privatechat-ul">
                            {
                                this.props.conversation.map((item, index) => {
                                    // console.log(this.getGetbusinessid(item.conversationID.replace('C2C', '')))
                                    return <li key={index}
                                        className="privatechat-li"
                                        onClick={() => {
                                            this.props.history.push({
                                                pathname: '/kefu',
                                                search: `business_id = ${this.getGetbusinessid(item.conversationID.replace('C2C', '')).business_id}`
                                            })
                                        }}
                                    >
                                        <img className="privatechat-img" src={`${imgInter}${this.getGetbusinessid(item.conversationID.replace('C2C', '')).business_pic}`}></img>
                                        <span className="privatechat-name"> {this.getGetbusinessid(item.conversationID.replace('C2C', '')).business_name}</span>
                                    </li>


                                })
                            }
                        </ul>
                        {/* </div> */}
                    </div>
                    <Mytab />
                </div>
                <div style={{ flex: '1' }}>
                </div>
            </div >
        )
    }
}
const mapStateToProps = (state) => ({
    login: state.login,
    // shop: state.shop,
    business: state.business,
    // shop_temp: state.shop_temp,
    conversation: state.conversation,
    message: state.message
})
export default withRouter(connect(mapStateToProps)(Message))